#include <func.h>

void signalhandler(int signum) {
    switch (signum) {
    case SIGINT:
        printf("Caught SIGINT\n");
        break;
    case SIGTSTP:
        printf("Caught SIGTSTP\n");
        break;
    case SIGABRT:
        printf("Caught SIGABRT\n");
        break;
    // ...
    default:
        printf("Unknown signal\n");
        break;
    }
}

int main(int argc, char* argv[])
{
    // 1. 注册信号处理函数
    sighandler_t oldhandler = signal(SIGINT, signalhandler);
    if (oldhandler == SIG_ERR) {
        perror("signal()");
        exit(1);
    }

    oldhandler = signal(SIGTSTP, signalhandler);
    if (oldhandler == SIG_ERR) {
        perror("signal()");
        exit(1);
    }

    /* oldhandler = signal(SIGKILL, signalhandler); */
    /* if (oldhandler == SIG_ERR) { */
    /*     fprintf(stderr, "signal(%d): %s\n", SIGKILL, strerror(errno)); */
    /*     exit(1); */
    /* } */

    for(;;) ;
    return 0;
}

